package com.yanfan.ccapi.service.impl;

import com.yanfan.ccapi.service.ICcapiDeviceService;
import com.yanfan.ccapicode.dao.DeviceRepository;
import com.yanfan.ccapicode.dao.entity.DeviceDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * 云云对接设备Service业务层处理
 *
 * @author kerwincui
 * @date 2025-06-29
 */
@Service
public class CcapiDeviceServiceImpl implements ICcapiDeviceService {
    @Autowired
    private DeviceRepository ccapiDeviceMapper;

    /**
     * 查询云云对接设备
     *
     * @param deviceId 云云对接设备主键
     * @return 云云对接设备
     */
    @Override
    public DeviceDO selectCcapiDeviceByDeviceId(Long deviceId) {
        return ccapiDeviceMapper.selectCcapiDeviceById(deviceId);
    }

    /**
     * 查询云云对接设备列表
     *
     * @param ccapiDevice 云云对接设备
     * @return 云云对接设备
     */
    @Override
    public List<DeviceDO> selectCcapiDeviceList(DeviceDO ccapiDevice) {
        return ccapiDeviceMapper.selectCcapiDeviceList(ccapiDevice);
    }

    /**
     * 新增云云对接设备
     *
     * @param ccapiDevice 云云对接设备
     * @return 结果
     */
    @Override
    public boolean insertCcapiDevice(DeviceDO ccapiDevice) {
        ccapiDevice.setCreateTime(LocalDateTime.now());
        return ccapiDeviceMapper.insertOrUpdate(ccapiDevice);
    }

    /**
     * 修改云云对接设备
     *
     * @param ccapiDevice 云云对接设备
     * @return 结果
     */
    @Override
    public boolean updateCcapiDevice(DeviceDO ccapiDevice) {
        ccapiDevice.setUpdateTime(LocalDateTime.now());
        return ccapiDeviceMapper.insertOrUpdate(ccapiDevice);
    }

    /**
     * 批量删除云云对接设备
     *
     * @param deviceIds 需要删除的云云对接设备主键
     * @return 结果
     */
    @Override
    public boolean deleteCcapiDeviceByDeviceIds(Long[] deviceIds) {
        return ccapiDeviceMapper.deleteByIds(Arrays.asList(deviceIds));
    }

    /**
     * 删除云云对接设备信息
     *
     * @param deviceId 云云对接设备主键
     * @return 结果
     */
    @Override
    public boolean deleteCcapiDeviceByDeviceId(Long deviceId) {
        return ccapiDeviceMapper.deleteById(deviceId);
    }
}
